package com.itheima.controller;


import com.itheima.pojo.Result;
import com.itheima.pojo.nursing.NursingLevel;
import com.itheima.pojo.nursing.NursingPlan;
import com.itheima.pojo.nursing.NursingPlanParam;
import com.itheima.service.NursingPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/nursingPlan")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    public Result page(NursingPlanParam nursingPlanParam){
        return Result.success(nursingPlanService.page(nursingPlanParam));
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        NursingPlan byId = nursingPlanService.getById(id);
        return Result.success(byId);
    }

    @PostMapping
    public Result add(@RequestBody NursingPlan nursingPlan){
        nursingPlan.setCreateTime(LocalDateTime.now());
        nursingPlan.setUpdateTime(LocalDateTime.now());
        nursingPlanService.save(nursingPlan);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody NursingPlan nursingPlan){
        nursingPlan.setUpdateTime(LocalDateTime.now());
        nursingPlanService.updateById(nursingPlan);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        nursingPlanService.removeByIds(ids);
        return Result.success();
    }
}
